/**********************************************************************************************************************
* COPYRIGHT 
* ------------------------------------------------------------------------------------------------------------------- 
* Copyright (c) iSOFT INFRASTRUCTURE SOFTWARE CO., LTD. This software is proprietary to 
* iSOFT INFRASTRUCTURE SOFTWARE CO., LTD., and all rights are reserved by iSOFT INFRASTRUCTURE SOFTWARE CO., LTD. 
* Without the express written permission of the company, no organization or individual may copy, install, trial, 
* distribute, or reverse engineer this software. For terms of use and further details, please refer to the End User 
* License Agreement (EULA) or contact us business@i-soft.com.cn for more assistance. 
* 
* This file contains code from EasyXMen, which is licensed under the LGPL-2.1. However, due to a special exception, 
* you are not required to comply with the provisions of section 6a of LGPL-2.1. Specifically, you may distribute 
* your software, including this file, under terms of your choice, including proprietary licenses, without needing to 
* provide the source code or object code as specified in section 6a. For more details, please refer to the project's 
* LICENSE and EXCEPTION files and the specific exception statement.  
* ------------------------------------------------------------------------------------------------------------------- 
* FILE DESCRIPTION 
* ------------------------------------------------------------------------------------------------------------------- 
*  @MCU                : S32K148 
*  @file               : Os_UserInf.c 
*  @license            : Evaliation 
*  @licenseExpiryDate  :  
*  @date               : 2024-10-21 10:37:16 
*  @customer           : EasyXMen User 
*  @toolVersion        : 2.0.18 
*********************************************************************************************************************/ 

/*=======[I N C L U D E S]====================================================*/
#include "Os.h"
#include "Arch_Extend.h"
#include "Arch_Processor.h"
/** DO NOT CHANGE THIS COMMENT!
 * <USERBLOCK User Includes>
 */
/* custom code.... */
#include "Gpt.h"
#include "Can_43_FLEXCAN.h"
#include "Mem_43_INFLS.h"
#include "MemAcc.h"
#include "EcuM.h"
#include "EcuM_Cbk.h"
#include "ComM.h"
#include "ComM_Gent.h"
#include "NvM.h"
#include "WdgM.h"
#include "Fee.h"
#include "Dem.h"
#include "MemIf_Types.h"
#include "SchM_Fee.h"
#include "SchM_MemAcc.h"
#include "SchM_CanSM.h"
#include "SchM_CanNm.h"
#include "SchM_NvM.h"
#include "SchM_Com.h"
#include "SchM_CanTp.h"
#include "SchM_Dcm.h"
#include "SchM_EcuM.h"
#include "SchM_BswM.h"
#include "SchM_Dem.h"
#include "SchM_WdgM.h"
/** DO NOT CHANGE THIS COMMENT!
 * </USERBLOCK User Includes>
 */
/*=======[V E R S I O N   I N F O R M A T I O N]===============================*/
#define     OS_USERAPP_C_AR_MAJOR_VERSION              19U
#define     OS_USERAPP_C_AR_MINOR_VERSION              11U
#define     OS_USERAPP_C_AR_PATCH_VERSION              0U
#define     OS_USERAPP_C_SW_MAJOR_VERSION              2U
#define     OS_USERAPP_C_SW_MINOR_VERSION              0U
#define     OS_USERAPP_C_SW_PATCH_VERSION              0U

/*=======[V E R S I O N  C H E C K]===========================================*/
#if (OS_USERAPP_C_AR_MAJOR_VERSION != OS_CFG_H_AR_MAJOR_VERSION)
    #error "Os_Userapp.c:Mismatch in Specification Major Version"
#endif
#if (OS_USERAPP_C_AR_MINOR_VERSION != OS_CFG_H_AR_MINOR_VERSION)
    #error "Os_Userapp.c:Mismatch in Specification Minor Version"
#endif
#if (OS_USERAPP_C_AR_PATCH_VERSION != OS_CFG_H_AR_PATCH_VERSION)
    #error "Os_Userapp.c:Mismatch in Specification Patch Version"
#endif
#if (OS_USERAPP_C_SW_MAJOR_VERSION != OS_CFG_H_SW_MAJOR_VERSION)
    #error "Os_Userapp.c:Mismatch in Specification Major Version"
#endif
#if (OS_USERAPP_C_SW_MINOR_VERSION != OS_CFG_H_SW_MINOR_VERSION)
    #error "Os_Userapp.c:Mismatch in Specification Minor Version"
#endif

/*=======[T A S K S]==========================================*/
/* PRQA S 1532++ */ /* MISRA Rule 8.7 */

/*OsTask_Init: Core0(CPU0),Type = BASIC, Priority = 1*/
TASK(OsTask_Init)
{
    /* please insert your code here ... */
    /** DO NOT CHANGE THIS COMMENT!
    * <USERBLOCK OsTask_Init >
    */
    /* custom code.... */
	uint32 NVM_USE_InitTIME = 0;
	uint32 INIT_READALL_TIMEOUT = 15000;
	NvM_RequestResultType InitNvMReadAllStatus = NVM_REQ_NOT_OK;

	EcuM_StartupTwo();

	Mem_43_INFLS_Init(NULL_PTR);
	MemAcc_Init(&MemAcc_Config);
	Fee_Init(NULL_PTR);
	NvM_Init(NULL_PTR);

	NvM_ReadAll();
	do
	{
		NVM_USE_InitTIME++;
		NvM_MainFunction();
		Fee_MainFunction();
		MemAcc_MainFunction();
		Mem_43_INFLS_MainFunction();
		NvM_GetErrorStatus(0,&InitNvMReadAllStatus);
		if(INIT_READALL_TIMEOUT < NVM_USE_InitTIME)
			break;
	}while(InitNvMReadAllStatus == NVM_REQ_PENDING);

	Dem_Init(&DemPbCfg);

    EcuM_SetWakeupEvent(EcuMWakeupSource_CAN);
    ComM_RequestComMode(0, COMM_FULL_COMMUNICATION);
    /** DO NOT CHANGE THIS COMMENT!
    * </USERBLOCK OsTask_Init >
    */
    if (E_OK != TerminateTask())
    {
        while (1)
        {
            /* dead loop */
        }
    }
}

/*OsTask_1ms: Core0(CPU0),Type = BASIC, Priority = 4*/
TASK(OsTask_1ms)
{
    /* please insert your code here ... */
    /** DO NOT CHANGE THIS COMMENT!
    * <USERBLOCK OsTask_1ms >
    */
    /* custom code.... */
	CanSM_MainFunction();
		WdgM_CheckpointReached(WdgMSupervisedEntity_0, SE0_WdgMCheckpoint_0);
		WdgM_MainFunction();
    /** DO NOT CHANGE THIS COMMENT!
    * </USERBLOCK OsTask_1ms >
    */
    if (E_OK != TerminateTask())
    {
        while (1)
        {
            /* dead loop */
        }
    }
}

void test();
/*OsTask_5ms: Core0(CPU0),Type = BASIC, Priority = 3*/
TASK(OsTask_5ms)
{
    /* please insert your code here ... */
    /** DO NOT CHANGE THIS COMMENT!
    * <USERBLOCK OsTask_5ms >
    */
    /* custom code.... */
    CanNm_MainFunction();
    ComM_MainFunction_Channel_CanController_0();
    Com_MainFunctionRx();
    Com_MainFunctionTx();

    CanTp_MainFunction();
    Dcm_MainFunction();
    test();
//    while(1);
    /** DO NOT CHANGE THIS COMMENT!
    * </USERBLOCK OsTask_5ms >
    */
    if (E_OK != TerminateTask())
    {
        while (1)
        {
            /* dead loop */
        }
    }
}

/*OsTask_10ms: Core0(CPU0),Type = BASIC, Priority = 2*/
TASK(OsTask_10ms)
{
    /* please insert your code here ... */
    /** DO NOT CHANGE THIS COMMENT!
    * <USERBLOCK OsTask_10ms >
    */
    /* custom code.... */
    EcuM_MainFunction();
    BswM_MainFunction();
    Dem_MainFunction();

    NvM_MainFunction();
    Fee_MainFunction();
	MemAcc_MainFunction();
	Mem_43_INFLS_MainFunction();
    /** DO NOT CHANGE THIS COMMENT!
    * </USERBLOCK OsTask_10ms >
    */
    if (E_OK != TerminateTask())
    {
        while (1)
        {
            /* dead loop */
        }
    }
}

/*OsTask_100ms: Core0(CPU0),Type = BASIC, Priority = 1*/
TASK(OsTask_100ms)
{
    /* please insert your code here ... */
    /** DO NOT CHANGE THIS COMMENT!
    * <USERBLOCK OsTask_100ms >
    */
    /* custom code.... */
//	WdgM_CheckpointReached(WdgMSupervisedEntity_0, SE0_WdgMCheckpoint_0);
//	WdgM_MainFunction();
    /** DO NOT CHANGE THIS COMMENT!
    * </USERBLOCK OsTask_100ms >
    */
    if (E_OK != TerminateTask())
    {
        while (1)
        {
            /* dead loop */
        }
    }
}

/*=======[H O O K S]================================================*/
FUNC(void, OS_APPL_CODE) IdleHook_Core0(void)
{
    /* please insert your code here ... */
    /** DO NOT CHANGE THIS COMMENT!
    * <USERBLOCK IdleHook_Core0>
    */
    /* custom code.... */
    /** DO NOT CHANGE THIS COMMENT!
    * </USERBLOCK IdleHook_Core0>
    */
}

/*=======[ALARM CALL BACK]==========================================*/

FUNC(void, OS_APPL_CODE) ErrorHook(StatusType Error)
{
    /***The code below is just for deleting the complier warning.***
    ***Please remove it and use your own code****/
    (void)Error;
    /***The code above is just for deleting the complier warning*/
    /* please insert your code here ... */
    /** DO NOT CHANGE THIS COMMENT!
    * <USERBLOCK ErrorHook>
    */
    /* custom code.... */
    /** DO NOT CHANGE THIS COMMENT!
    * </USERBLOCK ErrorHook>
    */
}

FUNC(void, OS_APPL_CODE) StartupHook(void)
{
    /* please insert your code here ... */
    /** DO NOT CHANGE THIS COMMENT!
    * <USERBLOCK StartupHook>
    */
    /* custom code.... */
    /** DO NOT CHANGE THIS COMMENT!
    * </USERBLOCK StartupHook>
    */
}

FUNC(void, OS_APPL_CODE) ShutdownHook(StatusType Error)
{
    /***The code below is just for deleting the complier warning.***
    ***Please remove it and use your own code****/
    (void)Error;
    /***The code above is just for deleting the complier warning*/
    /* please insert your code here ... */
    /** DO NOT CHANGE THIS COMMENT!
    * <USERBLOCK ShutdownHook>
    */
    /* custom code.... */
    /** DO NOT CHANGE THIS COMMENT!
    * </USERBLOCK ShutdownHook>
    */
}

/*=======[P A N I C H A N D L E R]================================*/
FUNC(void, OS_CODE) Arch_PanicHandler(void)
{
    /* please insert your code here ... */
}

/*=======[I S R S]================================================*/
/*
 *ISR(CAN0_ORed: Core0(CPU0))
 */
ISR(CAN0_ORed)
{
    /* please insert your code here ... */
    /** DO NOT CHANGE THIS COMMENT!
    * <USERBLOCK CAN0_ORed>
    */
    /* custom code.... */
	extern void CAN0_ORED_IRQHandler();
	CAN0_ORED_IRQHandler();
    /** DO NOT CHANGE THIS COMMENT!
    * </USERBLOCK CAN0_ORed>
    */
}

/*
 *ISR(CAN0_ORed_0_15_MB: Core0(CPU0))
 */
ISR(CAN0_ORed_0_15_MB)
{
    /* please insert your code here ... */
    /** DO NOT CHANGE THIS COMMENT!
    * <USERBLOCK CAN0_ORed_0_15_MB>
    */
    /* custom code.... */
	extern void CAN0_ORED_0_15_MB_IRQHandler();
	CAN0_ORED_0_15_MB_IRQHandler();
    /** DO NOT CHANGE THIS COMMENT!
    * </USERBLOCK CAN0_ORed_0_15_MB>
    */
}

/*
 *ISR(CAN0_ORed_16_31_MB: Core0(CPU0))
 */
ISR(CAN0_ORed_16_31_MB)
{
    /* please insert your code here ... */
    /** DO NOT CHANGE THIS COMMENT!
    * <USERBLOCK CAN0_ORed_16_31_MB>
    */
    /* custom code.... */
	extern void CAN0_ORED_16_31_MB_IRQHandler();
	CAN0_ORED_16_31_MB_IRQHandler();
    /** DO NOT CHANGE THIS COMMENT!
    * </USERBLOCK CAN0_ORed_16_31_MB>
    */
}

/*
 *ISR(FTM0_Ch0_Ch1: Core0(CPU0))
 */
ISR(FTM0_Ch0_Ch1)
{
    /* please insert your code here ... */
    /** DO NOT CHANGE THIS COMMENT!
    * <USERBLOCK FTM0_Ch0_Ch1>
    */
    /* custom code.... */
	extern void FTM_0_CH_0_CH_1_ISR();
	FTM_0_CH_0_CH_1_ISR();
    /** DO NOT CHANGE THIS COMMENT!
    * </USERBLOCK FTM0_Ch0_Ch1>
    */
}

/* PRQA S 1532-- */ /* MISRA Rule 8.7 */
/*=======[E N D   O F   F I L E]==============================================*/

